package ro.gateway.aida.obj;

import java.sql.Date;
import java.util.Comparator;
import java.util.List;


/**
 * Organization
 * @author Mihai Postelnicu <p>
 *  mihai@ro-gateway.org
 */
public class Organization extends LocalizedItem {
    protected Country country;
    private String countryISO3 = "";
    private String acronym = "";
    private int catID = -1;
    private long id = -1;
    private String countries;
    private String types;
    private String AIDAOrg = "";
    private String countryName;
    protected LangString name;
    protected LangString description;
    protected OrgType type;
    private List persons;
    private long userID = -1;
    private Date update;
    private String infoSource;
    private boolean selected;
    private String address1;
    private String address2;
    private String contactName;
    private String contactEmail;
    private String contactPhone;
    private String contactFax;
    private String contactURL;
    private boolean temporary;
    private String contactTitle;

	/**
	 * @return Returns the contactTitle.
	 */
	public String getContactTitle() {
		return contactTitle;
	}
	/**
	 * @param contactTitle The contactTitle to set.
	 */
	public void setContactTitle(String contactTitle) {
		this.contactTitle = contactTitle;
	}
    //get
    public Organization() {
        super();
        name = new LangString();
        description = new LangString();
        selected = false;
        temporary=false;
    }

    public Organization(String lang) {
        super();
        name = new LangString();
        description = new LangString();
        selected = false;
        temporary=false;
    }

    public String getCountryISO3() {
        return countryISO3;
    }

    public LangString getDescription() {
        return description;
    }

    public String getAcronym() {
        return acronym;
    }

    public LangString getName() {
        return name;
    }

    public int getCatID() {
        return catID;
    }

    public long getId() {
        return id;
    }

    public boolean hasId() {
        return this.id != -1;
    }

    public void setCountryISO3(String countryISO3) {
        this.countryISO3 = countryISO3;
    }

    public void setAcronym(String acronym) {
        this.acronym = acronym;
    }

    public void setCatID(int catID) {
        this.catID = catID;
    }

    public void setId(long orgID) {
        this.id = orgID;
    }

    public java.util.List getPersons() {
        return persons;
    }

    public void setPersons(java.util.List persons) {
        this.persons = persons;
    }

    public String getCountries() {
        return countries;
    }

    public void setCountries(String countries) {
        this.countries = countries;
    }

    public String getTypes() {
        return types;
    }

    public void setTypes(String types) {
        this.types = types;
    }

    public long getUserID() {
        return userID;
    }

    public void setUserID(long userID) {
        this.userID = userID;
    }

    /**
     * @return
     */
    public String getAIDAOrg() {
        return AIDAOrg;
    }

    /**
     * @param string
     */
    public void setAIDAOrg(String string) {
        AIDAOrg = string;
    }

    /**
     * @return
     */
    public String getCountryName() {
        return countryName;
    }

    /**
     * @param string
     */
    public void setCountryName(String string) {
        countryName = string;
    }

    /**
     * @return
     */
    public Date getUpdate() {
        return update;
    }

    /**
     * @param date
     */
    public void setUpdate(Date date) {
        update = date;
    }

    /**
     * @return
     */
    public OrgType getType() {
        return type;
    }

    /**
     * @param type
     */
    public void setType(OrgType type) {
        this.type = type;
    }

    /**
     * @return
     */
    public boolean isSelected() {
        return selected;
    }

    /**
     * @param b
     */
    public void setSelected(boolean b) {
        selected = b;
    }

    /**
     * @param string
     */
    public void setDescription(LangString string) {
        description = string;
    }

    /**
     * @param string
     */
    public void setName(LangString string) {
        name = string;
    }

    /**
     * @return
     */
    public String getContactEmail() {
        return contactEmail;
    }

    /**
     * @return
     */
    public String getRawContactFax() {
        return contactFax;
    }

    public String getContactFax() {
    	if(contactFax==null) return null;
        return contactFax.replace('#','-');
    }
    
    
    /**
     * @return
     */
    public String getContactName() {
        return contactName;
    }

    /**
     * @return
     */
    public String getContactPhone() {
    	if(contactPhone==null) return contactPhone;
        return contactPhone.replace('#','-');
    }
    
    public String getRawContactPhone() {
        return contactPhone;
    }

    public String getContactPhone(int id) {
    	if(contactPhone==null) return "";
        if(contactPhone.indexOf('#')==-1)
        	{
        		if(id!=3) return "";
        		return contactPhone;
        	}
        String parts[]=contactPhone.split("#");
        if(parts.length<id) return "";
        return parts[id-1];
    }

    public String getContactFax(int id) {
    	if(contactFax==null) return "";
        if(contactFax.indexOf('#')==-1)
        	{
        		if(id!=3) return "";
        		return contactFax;
        	}
        String parts[]=contactFax.split("#");
        if(parts.length<id) return "";
        return parts[id-1];
    }

    
    
    /**
     * @return
     */
    public String getContactURL() {
    	if(contactURL!=null && contactURL.indexOf("http://")==-1) return "http://"+contactURL; 
        return contactURL;
    }

    /**
     * @param string
     */
    public void setContactEmail(String string) {
        contactEmail = string;
    }

    /**
     * @param string
     */
    public void setContactFax(String string) {
        contactFax = string;
    }

    /**
     * @param string
     */
    public void setContactName(String string) {
        contactName = string;
    }

    /**
     * @param string
     */
    public void setContactPhone(String string) {
        contactPhone = string;
    }

    /**
     * @param string
     */
    public void setContactURL(String string) {
        contactURL = string;
    }

    /**
     * @return
     */
    public String getAddress1() {
        return address1;
    }

    /**
     * @return
     */
    public String getAddress2() {
        return address2;
    }

    /**
     * @param string
     */
    public void setAddress1(String string) {
        address1 = string;
    }

    /**
     * @param string
     */
    public void setAddress2(String string) {
        address2 = string;
    }

    /**
     * @return
     */
    public Country getCountry() {
        return country;
    }

    /**
     * @param country
     */
    public void setCountry(Country country) {
        this.country = country;
    }

    public static class DateComparator implements Comparator {
        public DateComparator() {
        }

        public int compare(Object o1, Object o2) {
            Organization org1 = (Organization) o1;
            Organization org2 = (Organization) o2;

            return (org1.getUpdate().compareTo(org2.getUpdate()));
        }
    }

    public static class CountryComparator implements Comparator {
        public CountryComparator() {
        }

        public int compare(Object o1, Object o2) {
            Organization org1 = (Organization) o1;
            Organization org2 = (Organization) o2;

            return (org1.getCountryName().compareTo(org2.getCountryName()));
        }
    }

    public static class LangComparator implements Comparator {
        protected String lang;

        public LangComparator(String lang) {
            this.lang = lang;
        }

        public int compare(Object o1, Object o2) {
            Organization org1 = (Organization) o1;
            Organization org2 = (Organization) o2;

            return (org1.getName().getString(lang).compareTo(org2.getName()
                                                                 .getString(lang)));
        }
    }

    public static final String EDIT_TAG = "EDITED_Organization";
    public static final String PEOPLE = "Edited_Organization_People";
	/**
	 * @return Returns the temporary.
	 */
	public boolean isTemporary() {
		return temporary;
	}
	/**
	 * @param temporary The temporary to set.
	 */
	public void setTemporary(boolean temporary) {
		this.temporary = temporary;
	}
    /**
     * @return Returns the infoSource.
     */
    public String getInfoSource() {
        if(infoSource==null) return "";
        return infoSource;
    }
    /**
     * @param infoSource The infoSource to set.
     */
    public void setInfoSource(String infoSource) {
        this.infoSource = infoSource;
    }
}
